import React, { PureComponent } from 'react';
import "../../../styles/Index/Home/Goods.scss"
import { goodlist } from "../../../api/index"
import { withRouter } from 'react-router-dom';

class Goods extends PureComponent {
    constructor(props) {
        super(props);
        this.state = {
            goodlist: [],
        }
    }
    async componentDidMount() {
        var res = await goodlist();
        // console.log(res.data.data);
        this.setState({ goodlist: res.data.data })
    }
    goGood(id) {
        this.props.history.push({ pathname: '/good', state: { id } });
    }
    render() {
        return (
            <div className='goods'>

                {
                    this.state.goodlist.map((item, index) => {
                        return (
                            <div className="item" key={index} onClick={() => { this.goGood(item.proid) }}>
                                <div className="pic">
                                    <img src={item.img1} alt="" />
                                </div>
                                <div className="text">
                                    <div className="name">{item.proname}</div>
                                    <div className="price">￥{item.originprice}</div>
                                </div>
                            </div>
                        )
                    })
                }
                <div className="nomore">
                    没有更多了~~~
                </div>
            </div>
        );
    }
}

export default withRouter(Goods);